package org.jetnuke.modules.weblinks;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.ActionForward;
import org.jetnuke.common.IAction;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IModuleInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.LinksLinks;
import org.jetnuke.entities.LinksModRequest;
import org.jetnuke.util.JetUtil;

public class ReportBroken implements IAction {
	int lid;

	public int getLid() {
		return lid;
	}

	public void setLid(int lid) {
		this.lid = lid;
	}

	public ActionForward exec(HttpServletRequest request,
			HttpServletResponse response, VelocityContext vc, IModuleInfo info,
			String op, IUserInfo ui, IAdminInfo ai) throws Exception {
		DataAccessDriver.getInst().newLinkLinkDAO().retrieveByPK(lid);
		LinksLinks lk = DataAccessDriver.getInst().newLinkLinkDAO().retrieveByPK(lid);//links_linksPeer.retrieveByPK(lid);
		LinksModRequest obj = new LinksModRequest();
		obj.setBROKENLINK(1);
		obj.setCID(lk.getCID());
		obj.setLID(lid);
		obj.setDESCRIPTION(lk.getDESCRIPTION());
		obj.setTITLE(lk.getTITLE());
		obj.setURL(lk.getURL());
		String user = "";
		if (ui != null)
			user = ui.getUname();
		obj.setMODIFYSUBMITTER(user);
		DataAccessDriver.getInst().newLinkModRequestDAO().addNew(obj);
		//links_modrequestPeer.doInsert(obj);
		JetUtil.redirect(vc,response,request.getContextPath()+"/do/web_links");
		return null;
	}

}
